/**
 * Created by bai on 2015/7/9.
 */
/**
 * Created by bai on 2015/7/8.
 */
/**
 * Created by bai on 2015/7/8.
 */
var ServerPhoneJS = function(){

    /*****************全局变量开始*****************************/
    var historyList =[];
    var lastPage_record="";
    var serviceBox = $('#serviceBox');
    var dishesList={};//菜品列表
    var arrActive = ['#subamendBillPage .dishInfo .chooseIco','.reasonOptions .notHealthy','.reasonOptions .notAll','.reasonOptions .loseBill','.reasonOptions .other'  ];
    var CPTOTALNUMBER=0;
    var RESERVEORTAKEOUTCPLISTFlag = true;
    var TODAYORDERRESERVEDIANCAIFLAG = false;
    var TODAYORDERLIST = null;
    var TABLEHASORDERID = {};
    var TODAYORDERSEARCH = 0;//1是就餐中的订单，2是预定中的订单，3是外卖中的订单，4是结账的订单
    var CLICKWHICHTABLEORDERING = "";
    var DIRECTLYORDERINGCLICKCHOOSETABLE= false;
    var SETINTERVALFLAG = {
        addCp:null,
        oneCpNumber:0
    };
    var BACKADDPORTEVENT = {//给返回按钮添加事件

        openTable:[]
    }
    /*****************全局变量结束*****************************/
    /**********************js对象  所有的事件开始****************************************/
    var clickArea={
        footerTask:function(obj){
            PhoneGapRemind.vibrateOfPhoneGap();
            showPage($('#mainPagetaskPage'))();
            //taskMainPage();
        },
        footerOrder:function(obj){
            PhoneGapRemind.vibrateOfPhoneGap();
            CLICKWHICHTABLEORDERING = "";
            DIRECTLYORDERINGCLICKCHOOSETABLE = true;
            //waitPage.showWaitTime();//显示等待页面
            $('#mainPageorderPage .cont_btm').html("");
            $('.cpPageFooterFatherNode .btmTrueGray ').data('function','btn_ConfirmCpList');
            showPage($('#mainPageorderPage'))();
            footerOrder();
        },
        footerMore:function(obj){

        },
        footerMine:function(obj){
            PhoneGapRemind.vibrateOfPhoneGap();
            Mine.mineBtn(showPage($('#mainPageminePage')));
        },
        /*登陆*/loginSystem:function(obj,fun){
            waitPage.showWaitTime();//显示等待页面
            var user = $("#subloginPage .nameText").val();
            var pwd = $("#subloginPage .pwdText").val();
            OrderingSystem.signIn(user, pwd, function (data) {
                waitPage.closeWaitTime()//关闭等待页面
                if(data.error>0){
                    alert('用户名或者密码错误')
                }else{
                    //taskServiceList();//添加服务列表
                    showPage($('#mainPagetaskPage'))();
                    var now = new Date();
                    now.setDate(now.getDate() + 2);
                            localStorage.setItem("bqcuser_name",data.data[0].username)
                     localStorage.setItem("bqcuser_PIN",data.data[0].pin)
                     localStorage.setItem("bqcuser_id",data.data[0].userId)
                   /* document.cookie =  "bqcuser_id=" + data.data[0].userId + ";expires=" + now.toString() + ";path=/";
                    document.cookie =  "bqcuser_name=" + data.data[0].username + ";expires=" + now.toString() + ";path=/";
                    document.cookie= "bqcuser_PIN=" + data.data[0].pin + ";expires=" + now.toString() + ";path=/";*/
                }

            });
        },
        /*返回*/headerGoBack:function( obj ){
            if(historyList.length<2){ return console.log('没有更早的记录了！'); }
            historyList.pop();
            showPage( $('#'+historyList[historyList.length-1]),{record:true} )();
            if(BACKADDPORTEVENT.openTable.length>0){
                BACKADDPORTEVENT.openTable.pop();
                if(BACKADDPORTEVENT.openTable.length==0){
                    OpenTable.clickBackCanlOrder();
                    //alert(1)
                }
            }
            //menuActive( historyList[historyList.length-1] );
        },
        /*任务界面上的预定*/ notAcceptReserve:function(){
            //alert(1)
            waitPage.showWaitTime();//显示等待页面
            Reserve.reserveListFun( showPage($('#suborderMainPage')));
            $('.headerAdd').data('function','header_addReserve')
            $('.modalBackToList').data('function','btnBackReserveList');



        },
        /*接受的预定详情里面的确定按钮*/btn_acceptedReserveOk:function(){
            waitPage.showWaitTime();//显示等待页面
            showPage($('#suborderMainPage'));
        },
        /*任务栏点击外卖*/notAcceptTakeOutPage:function(){
            waitPage.showWaitTime();//显示等待页面
            TakeOut.takeOutList( showPage($('#subTakeoutMainPage')));
            $('.modalBackToList').data('function','btnBackTakeOutList');
            $('.headerAdd').data('function','header_addTakeOut')
        },
        notAcceptWeinXinReserve:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.clickReserveNotAcceptedONReserveList(obj, showPage($('#mainPageWechatOrderPage')));

        },
        /*接受的预定详情*/acceptWeinXinReserve:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.acceptedReserveInfo(obj,showPage($('#mainPagemenuDetailPage')))

        },
        btn_reserveAcceptTask:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.acceptReserve(obj,showPage($('#suborderMainPage')))

        }  ,
        btn_reserveRefuseTask:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.refuseReserve(obj, showPage($('#subCancelTaskPage')))
        },
        btn_selectedNotLuoZhuo:function(){
            waitPage.showWaitTime();//显示等待页面
            Reserve.luoZhuoNo(showPage($('#suborderMainPage')));

            $('.chooseSeatIndexPage').hide();
            $('.chooseSeatIndexMain').hide();
        },
        /*落桌yes*/btn_selectedLuoZhuo:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.luozhuoShowList(obj, showPage($('#subchooseSeatPage')))

        },
        /*选择桌台*/btn_LetReserveChooseTable:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.luoZhuoSelecTable(obj,showPage($('#suborderMainPage')))
            //showPage($('#suborderMainPage'));
        },
        btnnotacceptTakeOut:function(obj){
            waitPage.showWaitTime();//显示等待页面
            TakeOut.notAcceptedTakeOutInfo(obj,showPage($('#subteamOrderPage')))


        },
        /*拒绝预定添加理由*/ btn_refuseReasonOk:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.refuseReserveReason(obj,showPage($('#suborderMainPage')));

        },
        /*表头添加预定按钮*/header_addReserve:function(){
            waitPage.showWaitTime();//显示等待页面
            Reserve.addBtnToAddReservePage( showPage($('#subaddOrderPage')))
            //showPage($('#subaddOrderPage'))();
            $('#submenuPage .btm').data('function','btn_addReserveOrderInfoOk')
        },
        /*表头添加外卖按钮*/header_addTakeOut:function(){

            $('#subtakeoutOrderPage .contDishes .dishes').html("菜品：");
            $('#subtakeoutOrderPage .demand').html("特殊需求：");

            showPage($('#subtakeoutOrderPage'))();
            $('#submenuPage .btm').data('function','btn_addTakeOutOrderInfoOk')
        },
        /*确认添加预定*/btn_confirmAddReserve:function(){
            waitPage.showWaitTime();//显示等待页面
            RESERVEORTAKEOUTCPLISTFlag=true;
            Reserve.addReserve(showPage($('#suborderMainPage')),TakingAnOrder.cpAddReserveOrTakeOutOrder);

        },
        /*点击添加预定的时候的时间*/btn_ReserveAddTime:function(){
            $('.addOrderTimeIndexPage').show();

        },
        /*添加预定时添加桌台种类*/btn_ReserveAddTableType:function(){
            $('#subaddOrderPage .addReserveAddTableType').show();
        },
        /*点击添加预定的时间后出现的蒙布*/ mengbuReserveTimeAndTable:function(){
            $('#subaddOrderPage .addOrderTimeIndexPage').hide();
            $('#subaddOrderPage .addReserveAddTableType').hide();
        },
        /*添加预定，点击选择时间后的事件*/choseTimeAddReserve:function(obj){
            //alert(obj.html())
            $('.createPreOrder_ResTime').html(obj.html());
            $('.addOrderTimeIndexPage').hide();
        },
        /*添加预定，选择桌台后的事件*/btn_addReserveTableType:function(obj){
            $('#subaddOrderPage .countText').html(obj.html());
            $('#subaddOrderPage .countText').data('id',obj.data('id'));
            $('#subaddOrderPage .addReserveAddTableType').hide();
        },
        /*添加预定选择桌台*/btn_addReserve_addTableDirectly:function(){
            waitPage.showWaitTime();//显示等待页面
            Reserve.addReserveSelectTable(showPage($('#subchooseSeatPage'),{record:true}));
        },
        /*桌台列表页面添加预定时选择桌台*/btn_tableList_addReserveTable:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.directChooseTableOfTableList(obj,showPage($('#subaddOrderPage')));
        },
        /*点击拒绝外卖*/ btn_refuseTakeOutTask:function(obj){
            waitPage.showWaitTime();//显示等待页面
            TakeOut.refuseTakeOut(obj,showPage($('#subcancelOrderPage')));

        },
        /*接受外卖*/btnacceptTakeOut:function(obj){
            waitPage.showWaitTime();//显示等待页面
            TakeOut.acceptedTakeOutInfo(obj,showPage($('#subteamOrderDetail')));

        },
        /*接受外卖*/btn_acceptTakeOutTask:function(obj){
            waitPage.showWaitTime();//显示等待页面
            TakeOut.acceptTakeOut(obj,showPage($('#subTakeoutMainPage')));

        },
        /*查看订单详情*/btn_goToTakeOutOrderInfo:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Reserve.clickReserveInfoRight(obj, showPage($('#subbillPage')));

        },
        /*拒绝外卖添加理由*/btn_refuseTakeOut:function(obj){
            waitPage.showWaitTime();//显示等待页面
            TakeOut.refuseTakeOutAddReason(obj,showPage($('#subTakeoutMainPage')));

        },
        /*添加外卖*/ btn_confirmAddTakeOut:function(){
            waitPage.showWaitTime();//显示等待页面
            RESERVEORTAKEOUTCPLISTFlag = true;
            TakeOut.addTakeOut(showPage($('#subTakeoutMainPage')),TakingAnOrder.cpAddReserveOrTakeOutOrder);

        },
        /*添加菜品*/btn_addCp:function(){
            ///showPage($('#suborderDishesPage'));

            if(RESERVEORTAKEOUTCPLISTFlag){
                TakingAnOrder.showDishes(showPage($('#suborderDishesPage')));
                $('.cpPageFooterFatherNode .btmTrueGray ').data('function','btn_addReserveOrTakeOut_cpList');
                $('.cpPageFooterFatherNode .ul-ShoppingCartCpList').html('');//清空购物车
                $('.cpPageFooterFatherNode .billCount').html(0);//购物车下的菜品的总数量
                CPTOTALNUMBER=0;
                RESERVEORTAKEOUTCPLISTFlag=false;
            }else{
                showPage($('#suborderDishesPage'))();
            }

        },
        /*弹框提示返回预定列表*/btnBackReserveList:function(){
            waitPage.showWaitTime();//显示等待页面
            $('.modalOrderIsAccepted').hide();
            Reserve.reserveListFun(showPage($('#suborderMainPage')));
        },
        /*弹框提示返回外卖列表*/btnBackTakeOutList:function(){
            waitPage.showWaitTime();//显示等待页面
            $('.modalOrderIsAccepted').hide();
            TakeOut.takeOutList(showPage($('#subTakeoutMainPage')));
        },

        /*添加一条菜品*/btn_cp_addOne:function(obj){
            /*      obj.parents('.dishesMenuList').find('.add').addClass('disabled');
             obj.removeClass('disabled');*/
            clearTimeout(SETINTERVALFLAG.addCp)
            var cpNumber = Number(obj.siblings('.cpNumber').html())+1;
            SETINTERVALFLAG.oneCpNumber=cpNumber
            if(SETINTERVALFLAG.oneCpNumber>=100){

            }else{
                $('.cpPageFooterFatherNode .billCount').html(++CPTOTALNUMBER+"份")

                TakingAnOrder.setTempLineItem(obj,cpNumber,CPTOTALNUMBER);
                cPaddMoreOrSubMore(function(){
                    var cpNumber = Number(obj.siblings('.cpNumber').html())+1;
                    SETINTERVALFLAG.oneCpNumber=cpNumber
                    $('.cpPageFooterFatherNode .billCount').html(++CPTOTALNUMBER+"份")

                    TakingAnOrder.setTempLineItem(obj,cpNumber,CPTOTALNUMBER);
                })//每次加很多菜
            }



        },
        /*减一条菜品*/btn_cp_subtractOne:function(obj){
            /*  obj.parents('.dishesMenuList').find('.cut').addClass('disabled');
             obj.removeClass('disabled');*/
            clearTimeout(SETINTERVALFLAG.addCp)
            var cpNumber = Number(obj.siblings('.cpNumber').html())-1;
            SETINTERVALFLAG.oneCpNumber=cpNumber;
            $('.cpPageFooterFatherNode .billCount').html(--CPTOTALNUMBER+"份")
            TakingAnOrder.setTempLineItem(obj,cpNumber,CPTOTALNUMBER);
            if(cpNumber<=0){

            }else{
                cPaddMoreOrSubMore(function(){
                    var cpNumber = Number(obj.siblings('.cpNumber').html())-1;
                    SETINTERVALFLAG.oneCpNumber=cpNumber

                    $('.cpPageFooterFatherNode .billCount').html(--CPTOTALNUMBER+"份")
                    TakingAnOrder.setTempLineItem(obj,cpNumber,CPTOTALNUMBER);
                })


            }



        },
        /********************点餐*******************************************/
        /*搜索菜品*/  btn_seek_cp :function(){
            TakingAnOrder.seekCp();
        },
        /*点击搜索栏中的字母组合*/btn_seek_combinatorics:function(obj){
            TakingAnOrder.clickSeekCombinatorics(obj);
        },
        /*点击购物车*/  btn_shoppingCart:function(){

            TakingAnOrder.shoppingCart();
        },
        /*点击购物车后出现的蒙布*/mengbuOfTakingAnOrder:function(){
            $('.btmShoppingCarHidden').removeClass('btmShoppingCarShow');
            $('.cpPageFooterFatherNode .shoppingCarIcoWhite').removeClass('active')
            $('#suborderDishesPage .IndexPage').hide();
        },
        /*点击购物车里的减按钮*/ btn_shoppingCutCp:function(obj){

            var cpNumber = parseInt(obj.siblings('.dishesCount').html())-1;

            $('.cpPageFooterFatherNode .billCount').html(--CPTOTALNUMBER+"份")
            TakingAnOrder.shoppingCartSetTempLineItem(obj,cpNumber,CPTOTALNUMBER)
        },
        /*点击购物车里加按钮*/btn_shoppingAddCp:function(obj){
            //alert( parseInt(obj.siblings('.dishesCount').html()))
            var cpNumber = parseInt(obj.siblings('.dishesCount').html())+1;

            $('.cpPageFooterFatherNode .billCount').html(++CPTOTALNUMBER+"份")
            TakingAnOrder.shoppingCartSetTempLineItem(obj,cpNumber,CPTOTALNUMBER)
        },
        /*点击弹出键盘*/btn_Keyboard:function(){
            $('.btmShoppingCarHidden').removeClass('btmShoppingCarShow');
            $('.cpPageFooterFatherNode .shoppingCarIcoWhite').removeClass('active')
            $('#suborderDishesPage .IndexPage').hide();
            if($('.cpPageFooterFatherNode .barAndKeysDown').hasClass('barAndKeysUp')){
                $('.cpPageFooterFatherNode .barAndKeysDown').removeClass('barAndKeysUp');
                $('.cpPageFooterFatherNode .keysIcoWhite').removeClass('active');
            }else{
                $('.cpPageFooterFatherNode .barAndKeysDown').addClass('barAndKeysUp');
                $('.cpPageFooterFatherNode .keysIcoWhite').addClass('active');

            }



        },
        /*点菜确认*/btn_ConfirmCpList:function(){
            if(BACKADDPORTEVENT.openTable.length>0){
                BACKADDPORTEVENT.openTable.push(2);
            }
            TakingAnOrder.cpListOk(showPage($('#subOrderDetailsPage')));
            //$('.cpPageFooterFatherNode').hide();
            //alert(1)
        },
        /*订单详情里的减按钮*/btn_shoppingOrderInfoCutCp:function(obj){
            clearTimeout(SETINTERVALFLAG.addCp)
            var cpNumber = parseInt(obj.siblings('.dishesCount').html())-1;
            SETINTERVALFLAG.oneCpNumber=cpNumber;
            $('.cpPageFooterFatherNode .billCount').html(--CPTOTALNUMBER+"份")
            TakingAnOrder.shoppingOrderCartSetTempLineItem(obj,cpNumber,CPTOTALNUMBER)
            if(cpNumber<=0){

            }else{
                cPaddMoreOrSubMore(function(){
                    var cpNumber = parseInt(obj.siblings('.dishesCount').html())-1;
                    SETINTERVALFLAG.oneCpNumber=cpNumber;
                    $('.cpPageFooterFatherNode .billCount').html(--CPTOTALNUMBER+"份")
                    TakingAnOrder.shoppingOrderCartSetTempLineItem(obj,cpNumber,CPTOTALNUMBER)
                })
            }


        },
        /*订单详情里的加按钮*/btn_shoppingOrderInfoAddCp:function(obj){
            clearTimeout(SETINTERVALFLAG.addCp)

            var cpNumber = parseInt(obj.siblings('.dishesCount').html())+1;
            SETINTERVALFLAG.oneCpNumber=cpNumber;
            if(SETINTERVALFLAG.oneCpNumber>=100){

            }else{
                $('.cpPageFooterFatherNode .billCount').html(++CPTOTALNUMBER+"份")
                TakingAnOrder.shoppingOrderCartSetTempLineItem(obj,cpNumber,CPTOTALNUMBER)
                cPaddMoreOrSubMore(function(){
                    var cpNumber = parseInt(obj.siblings('.dishesCount').html())+1;
                    SETINTERVALFLAG.oneCpNumber=cpNumber;
                    $('.cpPageFooterFatherNode .billCount').html(++CPTOTALNUMBER+"份")
                    TakingAnOrder.shoppingOrderCartSetTempLineItem(obj,cpNumber,CPTOTALNUMBER)
                })
            }


        },
        /*添加预定外卖时，点菜的确定按钮*/btn_addReserveOrTakeOut_cpList:function(obj){
            TakingAnOrder.reserveOrTakeOutCpOk(showPage($('#submenuPage')));
        },
        btn_addReserveOrderInfoOk:function(){
            TakingAnOrder.cpShowAddReserveOrTakeOut(showPage($('#subaddOrderPage')));
        },
        btn_addTakeOutOrderInfoOk:function(){
            TakingAnOrder.cpShowAddReserveOrTakeOut(showPage($('#subtakeoutOrderPage')));
        },
        /*点餐，菜品列表的确定按钮*/btn_orderingFood_orderInfo_ok:function(obj){

            waitPage.showWaitTime();//显示等待页面
            TakingAnOrder.cpListOrderInfoOk(obj,function(){
                if(TODAYORDERRESERVEDIANCAIFLAG){
                    TakingAnOrder.todayOrderReserveAddCpList(showPage($('#subtureTakeOneSeatPage')));
                }else{
                    footerOrder(showPage($('#mainPageorderPage')));
                }

            });
        },
        /********************服务***************************************/
        /*任务里加菜提醒*/btn_taskNotAcceptNewLineItem:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Service.notAcceptNewLineItem(obj,showPage($('#subAddDishesHandlePage')));
        },
        /*打印新加菜*/btn_printNewLineItem:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Service.printNewLineItem(obj,showPage($('#mainPagetaskPage')));
        },
        /*任务里未接受的服务*/ btn_taskNotAcceptServiceList:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Service.notAcceptServiceInfo(obj,showPage($('#subcallSeverPage')));
        },
        /*任务里接受的服务*/btn_taskAcceptServiceList:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Service.acceptSeviceInfo(obj,showPage($('#subdealSeverPage')));
        },
        /*接受服务*/btn_accpetServiceCall:function(obj,fun){
            waitPage.showWaitTime();//显示等待页面
            Service.acceptSevice(obj,showPage($('#mainPagetaskPage')));
        },
        back_TaskseviceList:function(){
            waitPage.showWaitTime();//显示等待页面
            $('#subcallSeverPage .IndexPage').hide();
            $('#subcallSeverPage .sorryIndexMain').hide();
            showPage($('#mainPagetaskPage'))
            //Service.taskServiceList(showPage($('#mainPagetaskPage')));
        },
        /**********************开台**************************************/
        /*直接点击空台*/btn_open_table_empty:function(obj){
            CLICKWHICHTABLEORDERING = obj.data('id');
            waitPage.showWaitTime();//显示等待页面
            $('#subOrderDetailsPage .btmTrue').data('function','btn_orderingFood_orderInfo_ok');
            OpenTable.emptyTableOpen(obj,showPage($('#subfoundingOrderPage')));
        },
        /*空台点击开台点餐*/btn_orderingFood_clickCpOrdering:function(obj){
            BACKADDPORTEVENT.openTable.push(1);
            waitPage.showWaitTime();//显示等待页面
            CPTOTALNUMBER=0;
            $('.cpPageFooterFatherNode .btmTrueGray ').data('function','btn_ConfirmCpList');

            OpenTable.emptyTableOpenClickCpOrder(obj,function(){showPage($('#suborderDishesPage'))();},TakingAnOrder.showDishes);

        },
        /*空台开台 预定桌台开台*/btn_orderingFood_reserveLuoZhuo:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.emptyTableOpenClickReserveToTable(obj,showPage($('#suborderAndSearchPage')))
        },
        /*空台开台，点击预定订单*/btn_orderingFood_emptyTable_reserve_luoZhuo:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.emptyTableClickReserveOrderLuoZhuo(obj,function(){
                footerOrder(showPage($('#mainPageorderPage')));
            })
        },
        /*********点餐,预定流程************/
        /*预定桌台开台*/btn_open_table_reserve:function(obj,fun){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveTableOpen(obj,showPage($('#subtureTakeOneSeatPage')));
        },
        /*预定桌台确认落座*/btn_orderingFood_reserve_LuoZuoOk:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveLuoZuoOk(obj,showPage($('#suborderingFoodchooseSeatPage')));
        },
        /*预定桌台换台*/btn_orderingFood_reserve_exchange:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveChangeTable(obj,showPage($('#suborderingFoodchooseSeatPage')));
        },
        /*预定桌台清除预定*/btn_orderingFood_reserve_clearAwayReserve:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveClearOrder(obj,showPage($('#subClearReserveOrderTaskPage')));
        },
        /*预定桌台不点菜*/btn_orderingFood_reserve_noChooseCp:function(){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveNoChooseCp(showPage($('#mainPageorderPage')));
        },
        /*预定桌台点菜*/btn_orderingFood_reserve_chooseCp:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveChooseCp(obj,showPage($('#suborderDishesPage')));
        },
        /*确认清除*/btn_orderingFood_clearReserveOrder:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.reserveOrderClearOk(obj,showPage($('#mainPageorderPage')));
        },
        /*预定落桌，选桌台*/btn_orderingFood_reserveList_tableList:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OpenTable.todayOrderReserveLuoZhuo(obj,function(){    footerOrder(showPage($('#mainPageorderPage')));});
        },
        /*预定订单选菜*/todayOrder_reserve_chooseCp:function(obj){

            //更换菜品点菜后的菜品列表详情里的确定按钮data-function
            TODAYORDERRESERVEDIANCAIFLAG = true;
            CPTOTALNUMBER=0;
            $('#subOrderDetailsPage .btmTrue').data('function','btn_orderingFood_orderInfo_ok');
            OccupyTable.occupyTableAddCp(obj,function(){
                TakingAnOrder.showDishes(showPage($('#suborderDishesPage')),obj.data('id'));
            })
        },
        /******就餐中桌台流程*********/
        /*占用桌操作*/btn_occupy_table_operate:function(obj){
            CLICKWHICHTABLEORDERING = obj.data('id');
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.occupyFlowStart(obj,showPage($('#subchangeOneSeatPage')));
        },
        /*账单详情按钮，》*/btn_orderingFood_occupyTable_Cp:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.occupyTableCpInfo(obj,showPage($('#subBillDetailsPage')))
        },
        /*占用桌转台*/btn_orderingFood_occupyTable_changeTable:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.occupyTableExchangeTable(obj,showPage($('#suborderingFoodchooseSeatPage')));
        },
        /*占用桌转台，点击桌台列表*/btn_orderingFood_occupyTable_tableList_changeTable:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.occupyTableChangeTableClickTableList(obj,function(){
                footerOrder(showPage($('#mainPageorderPage')));
            });
        },
        /*占用桌加菜*/btn_orderingFood_occupyTable_addCp:function(obj){
            waitPage.showWaitTime();//显示等待页面
            //更换菜品点菜后的菜品列表详情里的确定按钮data-function
            CPTOTALNUMBER=0;
            $('#subOrderDetailsPage .btmTrue').data('function','btn_orderingFood_orderInfo_ok');
            OccupyTable.occupyTableAddCp(obj,function(){
                TakingAnOrder.showDishes(showPage($('#suborderDishesPage')),obj.data('id'));
            })
        },
        /*占用桌划菜*/btn_orderingFood_occupyTable_elideCp:function(obj){
            waitPage.showWaitTime();  //显示等待页面
            OccupyTable.occupyTableElideCp(obj,showPage($('#subcutDishesPage')));
        },
        /*每一道菜划菜*/btn_orderingFood_crossFood:function(obj){
            //obj.parent().addClass('active');

            if(obj.parent().hasClass('active')){
                //alert(obj.parent().hasClass('active'))
                obj.parent().removeClass('active');

            }else{
                obj.parent().addClass('active');

            }


        },
        /*占用桌退菜*/btn_orderingFood_occupyTable_deleteCp:function(obj){
            waitPage.showWaitTime();  //显示等待页面
            OccupyTable.occupyTableDeleteCp(obj,showPage($('#subdelDishesPage')));
        },
        /*占用桌免单*/btn_orderingFood_occupyTable_freeCp:function(obj){
            waitPage.showWaitTime();  //显示等待页面
            OccupyTable.occupyTableFreeCp(obj,showPage($('#subfreeBillPage')));
        },
        /*占用桌结账*/btn_orderingFood_occupyTable_billOrder:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.occupyTableBillOrder(obj,showPage($('#subchoosePayWayPage')));
        },
        /* 占用桌的菜的详细信息 */todayOrdering_billed_info:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.billTableCpInfo(obj,showPage($('#subBillDetailsPage')))
        },
        /*优惠券的下拉列表*/btn_orderingFood_coupon_list_down:function(obj){
            //alert(obj.css('display'))
            if($('#subchoosePayWayPage .showCouponOption').css('display')=='none'){
                $('#subchoosePayWayPage .showCouponOption').show();
            }else{
                $('#subchoosePayWayPage .showCouponOption').hide();
            }
        },
        /*支付方式*/btn_orderingFood_payWay:function(obj){
            if(obj.data('key') == "member"){
                waitPage.showWaitTime();//显示等待页面
            }
            OccupyTable.chooseWhichWay(obj,function(){
                footerOrder(showPage($('#subVipMainPage')));
            });
        },
        /*扫码支付*/btn_orderingFood_payWay_saoma:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.saomaPay(obj,showPage($('#subscanCodePage')));
        },
        /*点击一个优惠券*/btn_orderingFood_one_coupon:function(obj){

            OccupyTable.clickOneCoupon(obj);
        },
        /*确认划菜*/btn_orderingFood_elideCp_ok:function(){
            OccupyTable.elideCpOk();
        },
        /*是否划菜，不划菜*/btn_orderingFood_elideCpIsOrNo_no:function(){
            OccupyTable.elideCpIsOrNoNo();
        },
        /*是否划菜，确定划菜*/btn_orderingFood_elideCpIsOrNo_yes:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.elideCpIsOrNoYes(obj,function(){
                footerOrder(showPage($('#mainPageorderPage')))
            });
        },
        /*退掉菜品*/btn_orderingFood_deleteCp:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.deleteCp(obj,showPage($('#subdelDishesPage')));
        },
        /*菜品免单*/btn_orderingFood_freeFood:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.cpFree(obj,showPage($('#subfreeBillPage')));
        },
        /*退菜页面选中所有菜品*/btn_orderingFood_deleteOrFree_allChoose:function(obj){
            OccupyTable.allChoose(obj);
        },
        /*退菜页面选中单个菜品*/btn_orderingFood_deleteOrFree_oneChoose:function(obj){
            OccupyTable.oneChoose(obj);
        },
        /*退菜页面中的减号按钮*/btn_orderingFood_deleteOrFree_subtract:function(obj){
            OccupyTable.subtractCpCount(obj);
        },
        /*退菜页面中的加号按钮*/btn_orderingFood_deleteOrFree_add:function(obj){
            OccupyTable.addCpCount(obj);
        },
        /*免单页面中的全选*/btn_orderingFood_Free_allChoose:function(obj){
            if(obj.hasClass('active')){
                $('#subfreeBillPage .dishInfo').removeClass('active');
                $('#subfreeBillPage .chooseIco').removeClass('active');
            }else{
                $('#subfreeBillPage .dishInfo').addClass('active');
                $('#subfreeBillPage .chooseIco').addClass('active');
            }
        },
        /*免单页面中的选单个菜品*/btn_orderingFood_Free_oneChoose:function(obj){
            if(obj.hasClass('active')){
                obj.removeClass('active');
                obj.parents('.dishInfo').removeClass('active');
                $('#subfreeBillPage .chooseAllInfo').find('.chooseIco').removeClass('active');
            }else{
                obj.addClass('active');
                obj.parents('.dishInfo').addClass('active');
                var a = true;
                $('#subfreeBillPage .dishInfo').each(function(){
                    if(!$(this).hasClass('active')){
                        a = false;
                    }
                });
                if(a){
                    $('#subfreeBillPage .chooseAllInfo').find('.chooseIco').addClass('active');
                }
            }
        },
        /*菜品免单确定按钮*/btn_orderingFood_freeCp_comfirm:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.cpFreeOk(obj,showPage($('#mainPageorderPage')))
        },
        /*菜品退菜确定按钮*/btn_orderingFood_deleteCp_comfirm:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.deleteCpOk(obj,showPage($('#subchangeOneSeatPage')))
        },
        /*结账的收款按钮*/btn_orderingFood_billGetMoney:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.biilGetMoney(obj,function(){
                footerOrder(showPage($('#mainPageorderPage')));
            })
        },
        /*收款选择会员*/btn_orderingFood_chooseMember:function(obj){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.chooseMember(obj,function(){
                footerOrder(showPage($('#subVipPayPage')));
            });
        },
        /*会员支付页面结账按钮*/btn_orderingFood_billGetMoney_member:function(obj){
            if(!obj.hasClass("active")){
                waitPage.showWaitTime();//显示等待页面
                OccupyTable.biilGetMoneyMember(function(){
                    footerOrder(showPage($('#mainPageorderPage')));
                })
            }
        },
        /*余额不足选择其他支付方式*/btn_chooseOtherPayWay:function(){
            waitPage.showWaitTime();//显示等待页面
            OccupyTable.chooseOtherPayWay(function(){
                footerOrder(showPage($('#subchangeOneSeatPage')));
            })
        },
        /****点餐主页面直接点餐*****/
        /*直接点餐*/orderingfood_directChooseCp:function(){
            waitPage.showWaitTime();//显示等待页面
            CPTOTALNUMBER=0;
            TakingAnOrder.directClickCpOfMianPage(showPage($('#suborderDishesPage')));
        },
        /*选菜的订单详情*/btn_orderingFood_directClickCp_cpListInfoOK:function(obj){
            TakingAnOrder.chooseCpOrderingFoodCpInfoOk(obj);
        },
        /*选菜后落桌Ok*/btn_orderingFood_luoZhuoOk:function(obj){
            waitPage.showWaitTime();//显示等待页面
            TakingAnOrder.chooseCpToTable(obj,showPage($('#suborderingFoodchooseSeatPage')));
        },
        /*选择桌台落桌*/btn_orderingFood_tableList_directlyClickCpTable:function(obj){
            CLICKWHICHTABLEORDERING = obj.data('id');
            waitPage.showWaitTime();//显示等待页面
            TakingAnOrder.chooseTableLuoZhuo(obj,function(){
                footerOrder(showPage($('#mainPageorderPage')));
            })
        },
        /******点餐主页面今日账单***********/
        /*今日账单*/orderingfood_todayOrderList:function(){
            showPage($('#subtodayBillOfMealPage'))();
            waitPage.showWaitTime();//加载等待页面
            var todayOrderList = $('#subtodayBillOfMealPage');
            $('.bottom',todayOrderList).find('.active').removeClass('active');
            $('.bottom .mealBtn',todayOrderList).addClass('active');
            $('.searchInput',todayOrderList).val("");
            todayOrderEatingFood();
            //todayOrderListOfMainPage(showPage($('#subtodayBillOfMealPage')));
        },

        /*今日账单点餐中*/todayOrderListBottomEatingFood:function(obj){
            waitPage.showWaitTime();//加载等待页面
            todayOrderEatingFood();
            obj.parents('.bottom').find('.active').removeClass('active');
            obj.addClass('active');
            obj.parent().addClass('active');
            var parentNode =  $('#subtodayBillOfMealPage');
            $('.cont',parentNode).html('');
            $('.searchInput',parentNode).val('');
        },
        /*今日账单预定中*/todayOrderListBottomReserve:function(obj){
            waitPage.showWaitTime();//加载等待页面
            todayOrderListReserveOrderList();
            obj.parents('.bottom').find('.active').removeClass('active');
            obj.addClass('active');
            obj.parent().addClass('active');
            var parentNode =  $('#subtodayBillOfMealPage');
            $('.cont',parentNode).html('');
            $('.searchInput',parentNode).val('');

        },
        /*今日账单外卖*/todayOrderListBottomTakeOut:function(obj){
            waitPage.showWaitTime();//加载等待页面
            todayOrderTakeOutOrderList();
            obj.parents('.bottom').find('.active').removeClass('active');
            obj.addClass('active');
            obj.parent().addClass('active');
            var parentNode =  $('#subtodayBillOfMealPage');
            $('.cont',parentNode).html('');
            $('.searchInput',parentNode).val('');
        },
        /*今日账单结算*/todayOrderListBottomBill:function(obj){
            waitPage.showWaitTime();//加载等待页面
            todayOrderBillOrderList();
            obj.parents('.bottom').find('.active').removeClass('active');
            obj.addClass('active');
            obj.parent().addClass('active');
            var parentNode =  $('#subtodayBillOfMealPage');
            $('.cont',parentNode).html('');
            $('.searchInput',parentNode).val('');
        },
        /*今日订单搜索*/today_order_search:function(){
            todayOrderSearch();
        },
        /*就餐中 未结账*/btn_orderingFood_eatingFood_notBill:function(){
            showPage($('#subchangeOneSeatPage'))();
        },
        /*就餐中，已结账*/btn_orderingFood_eatingFood_billed:function(){
            showPage($('#subchangeOneSeatPage'))();
        },
        /*待结单，预定中的订单*/btn_orderingFood_todayOrder_reserving:function(){
            showPage($('#mainPageWechatOrderPage'))();
        },
        /*待接单，外卖的订单*/btn_orderingFood_todayOrder_takeOut:function(){
            showPage($('#subteamOrderPage'))();
        },

        /*已接单*/btn_orderingFood_todayOrder_alreadyAcceptOrder:function(){
            showPage($('#subtureTakeOneSeatPage'))();
        },
        /*已结账*/btn_orderingFood_billOrder_billed:function(obj){
            waitPage.showWaitTime();//显示等待页面
            alreadyBilledOrderInfo(obj,showPage($('#subtableOrderDetailsPage')));
            //showPage($('#subtureTakeOneSeatPage'))();
        },
        /***************************我的流程开始***************************************************************/
        /*主页面上的交班按钮*/btn_mine_shiftExchange:function(){
            waitPage.showWaitTime();//显示等待页面
            $('.header .select').data('function','header_selectShiftExchange');
            Mine.shiftExchange(showPage($('#subhandOverWorkPage')));
        },
        /*主页面的绩效按钮*/btn_mine_performance:function(){
            waitPage.showWaitTime();//显示等待页面
            $('.header .select').data('function','header_selectPerformance');
            Mine.performance(showPage($('#subperformancePage')));
        },
        /*主页面的网络按钮*/btn_mine_netWork:function(){
            Mine.netWork();
        },
        /*交班的确定按钮*/btn_mine_shiftExchangeOk:function(){
            Mine.shiftExchangeOk();
        },
        /*弹出框不交班*/btn_mine_promptCancleExchange:function(){
            Mine.shiftExchangePromptNot();
        },
        /*弹出框交班*/btn_mine_prompCtonfirmExchange:function(){
            waitPage.showWaitTime();//显示等待页面
            Mine.shiftExchangePromptYes(showPage($('#mainPageminePage')))
        },
        /*查询交班*/header_selectShiftExchange:function(){
            waitPage.showWaitTime();//显示等待页面
            Mine.inquireShiftExchange(showPage($('#subpayRecordPage')));
        },
        /*查询绩效*/header_selectPerformance:function(){
            Mine.inquirePerformance();
        },
        /*绩效查询的确定按钮*/btn_mine_performanceTimeOk:function(){
            Mine.inquirePerformanceSelectTimeOk();
        },
        /*查询当天的历史记录*/btn_mineShiftExchageHistory:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.seeOneHistoryOneDay(obj,showPage($('#subpayOneDayPage')));
        },
        /*查询一条历史记录*/btn_mineShiftExchageHistoryOne:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.seeOneHistoryRecord(obj,showPage($('#subhandOverWorkRecordPage')));
        },
        /*现金支付交班*/btn_minePayWayCashShiftExchange:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.shiftExchangePayWayOfCash(obj,showPage($('#subcashPayRecordPage')));
        },
        /*划卡支付交班*/btn_minePayWayPosShiftExchange:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.shiftExchangePayWayOfPos(obj,showPage($('#subcardPayRecordPage')));
        },
        /*网络支付交班*/btn_minePayWayNetShiftExchange:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.shiftExchangePayWayOfNet(obj,showPage($('#subnetPayRecordPage')));
        },
        /*现金支付*/btn_minePayWayCash:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.cashPay(obj,showPage($('#subcashPayRecordPage')));
        },
        /*pos支付*/btn_minePayWayPos:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.posPay(obj,showPage($('#subcardPayRecordPage')));
        },
        /*网络支付*/btn_minePayWayNet:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.netWorkPay(obj,showPage($('#subnetPayRecordPage')));
        },
        /*绩效，处理服务*/btn_mine_dealWithServe:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.dealWithSevice(obj,showPage($('#subperformanceServePage')));
        },
        /*绩效，处理预定*/btn_mine_dealWithReserve:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.dealWithReserve(obj,showPage($('#subperformanceOrderPage')));
        },
        /*绩效，处理外卖*/btn_mine_dealTakeOut:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.dealWithTakeOut(obj,showPage($('#subperformanceTakeoutPage')));
        },
        /*绩效，处理结算订单*/btn_mine_dealBilled:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.dealWithBillOrder(obj,showPage($('#subperformanceBillCheckPage')));
        },
        /*绩效，推广任务*/btn_mine_promoteTheTask:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.dealWithPromoteTheTask(obj,showPage($('#subperformanceSpreadPage')));
        },
        /*绩效，好评率*/btn_mine_goodProbability:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Mine.dealWithGoodProbability(obj,showPage($('#subperformanceAssessPage')));
        },
        /*绩效查询，点击开始时间*/btn_mine_performanceStartTime:function(){

            Mine.performanceClickStartTime();
        },
        /*绩效查询，点击结束时间*/btn_mine_performanceEndTime:function(){
            Mine.performanceClickEndTime();
        },
        /*点击月份*/btn_mine_performanceMonth:function(){
            Mine.performanceClickMonth();
        },
        /*点击日*/btn_mine_performanceDate:function(){
            Mine.performanceClickDate();
        },
        /*点击日*/btn_mine_performanceHour:function(){
            Mine.performanceClickHour();
        },
        /*点击日*/btn_mine_performanceMinute:function(){
            Mine.performanceClickMinute();
        },
        /*点击月的下拉列表*/btn_mine_chooseOneMonth:function(obj){
            Mine.clickMonthSelect(obj);
        },
        /*点击日的下拉列表*/btn_mine_chooseOneDate:function(obj){
            Mine.clickDateSelect(obj);
        },
        /*点击小时的下拉列表*/btn_mine_chooseOneHour:function(obj){
            Mine.clickHourSelect(obj);
        },
        /*点击分钟的下拉列表*/btn_mine_chooseOneMinute:function(obj){
            Mine.clickMinuteSelect(obj)
        },
        /*点击绩效的蒙布*/btn_mine_mengbuPerformance:function(){
            var parensNode = $('#subperformancePage');
            $('.monthList',parensNode).hide();
            $('.dayList',parensNode).hide();
            $('.hourList',parensNode).hide();
            $('.minuteList',parensNode).hide();
        },



        /***************************我的流程结束***************************************************************/
        /********************************会员流程开始************************************************/
        /*会员流程入口，打开会员列表一页*/ member_entrance:function(){
            waitPage.showWaitTime();//显示等待页面
            //alert(1)
            Member.memberEntrance(showPage($('#subMemberSearch')));
        },
        /*每条会员的信息*/btn_memberList_oneInfo:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Member.oneMemberInfo(obj,showPage($('#subMemberDetailed')));
        },
        /*添加会员*/header_addMember:function(){
            waitPage.showWaitTime();//显示等待页面
            Member.addMember(showPage($('#subAddMember')));
        },
        /*添加会员确定按钮*/btn_member_addMemberOk:function(){
            waitPage.showWaitTime();//显示等待页面
            Member.addMemberOk(showPage($('#subMemberSearch')));
        },
        /*会员的充值详情*/btn_member_recharge_info:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Member.memberRechargeInfo(obj,showPage($('#subMemberBill')));
        },
        /*会员消费详情*/btn_member_consumed_info:function(obj){
            waitPage.showWaitTime();//显示等待页面
            Member.memberConsumedInfo(obj,showPage($('#subMemberBill')));
        },
        /*会员充值的确定按钮*/btn_member_recharge_ok:function(obj){
            Member.memberRechargeOk(obj);
        },
        /*打印会员流水*/btn_member_printerWater:function(obj){
            Member.printerMemberWater(obj);
        },
        /*冻结会员或者激活会员*/btn_member_setMemberStatus:function(obj){

            Member.freezeOrActiveMember(obj)
        },
        /*搜索会员ok*/btn_member_selectOk:function(){
            Member.seekMemmber();
        }
        /********************************会员流程结束************************************************/


    }
    /**********************js对象  所有的事件结束****************************************/
    /*******************************（任务，点餐，更多，我的）的函数开始****************************************/
    /*
     * 给选菜品那页的确定加上disabled
     * */
    var addOrRemoveCpOkDisabled = function(){
        var parentsNode = $('#suborderDishesPage');
        if(CPTOTALNUMBER>0){
            $('.btmTrueGray ',parentsNode).removeClass('disabled');
        }else{
            $('.btmTrueGray ',parentsNode).addClass('disabled');
        }
    }
    /*
     * 师傅的排序
     * */
    var getSortFun = function(order, sortBy) { //排序函数
        var ordAlpah = (order == 'asc') ? '>' : '<';
        var sortFun = new Function('a', 'b', 'return a.' + sortBy + ordAlpah + 'b.' + sortBy + '?1:-1');
        return sortFun;
    }
    /*
     * 我的排序，为了桌台顺序
     * */
    var arrayJsonSortFromSmallToBig = function (array, pnam) {

        function creatJsonSort(pname) {
            return function (object1, object2) {
//                var value1 = parseInt(object1[pname]);
//                var value2 = parseInt(object2[pname]);
                var value1 = null;
                var value2 = null;
                if (parseInt(object1[pname])) {
                    value1 = parseInt(object1[pname]);
                }
                if (parseInt(object2[pname])) {
                    value2 = parseInt(object2[pname]);
                }

                if (value1 < value2) {
                    return -1;
                } else if (value1 > value2) {
                    return 1;
                } else {
                    return 0;
                }
            }
        }

        array.sort(creatJsonSort(pnam));
    }
    /*
     * 获得时间
     * */
    var getTimeOrder = function(timeorder){
        var time=new Date(timeorder*1000);
        time=time.getHours()+":"+time.getMinutes();
        return time;
    }
    /*
     * 任务主页面
     * */
    var taskMainPage = function(){
        notAcceptReserveAndTakeOutNumberOnTaskPage();//任务界面的未接受预定外卖数量
        taskServiceList();//添加服务列表
    }
    /*
     * 点餐主页面
     * */
    var footerOrder = function(fun){

        OrderingSystem.getTableList(function (data) {
            BACKADDPORTEVENT.openTable = [];
            waitPage.closeWaitTime()
            var listData=data.data;
            arrayJsonSortFromSmallToBig(listData, 'label');
            $('#mainPageorderPage .cont_btm').html('');
            var capital = ['','壹','贰','叁','肆','伍','陆','柒','捌','玖','拾']
            if(fun){

                fun();
                document.documentElement.scrollTop=0
            }
            $.each(listData,function(k,v){
                if(v.id==CLICKWHICHTABLEORDERING){

                    var number=(v.tableCap<11)?capital[v.tableCap]:"拾";

                    if(v.tableStatus=="OPEN"){
                        $('<li class="btm_list backgroundColorDisappear"  data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'" >\
                      <div class="btm_ico_box" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">'+number+'</div>\
                      </div>\
                      <p class="btm_title" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">'+v.label+'（空）</p>\
                      </li>').appendTo('#mainPageorderPage .cont_btm');
                    }else{
                        $('<li class="btm_list" style="background-color:#67ca67" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico_box" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">'+number+'</div>\
                      </div>\
                      <p class="btm_title" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">'+v.label+'（就餐中）</p>\
                      </li>').appendTo('#mainPageorderPage .cont_btm');
                    }
                }

            })
            $.each(listData,function(k,v){
                if(v.id==CLICKWHICHTABLEORDERING){
                    /*  var number=(v.tableCap<11)?capital[v.tableCap]:"拾";

                     if(v.tableStatus=="OPEN"){
                     $('<li class="btm_list backgroundColorDisappear"  data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'" >\
                     <div class="btm_ico_box" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">\
                     <div class="btm_ico" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">'+number+'</div>\
                     </div>\
                     <p class="btm_title" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">'+v.label+'（空）</p>\
                     </li>').appendTo('#mainPageorderPage .cont_btm');
                     }else{
                     $('<li class="btm_list" style="background-color:#67ca67" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">\
                     <div class="btm_ico_box" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">\
                     <div class="btm_ico" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">'+number+'</div>\
                     </div>\
                     <p class="btm_title" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">'+v.label+'（就餐中）</p>\
                     </li>').appendTo('#mainPageorderPage .cont_btm');
                     }*/
                }else{
                    var number=(v.tableCap<11)?capital[v.tableCap]:"拾";
                    if(v.tableStatus=="OPEN"){
                        $('<li class="btm_list" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico_box" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">'+number+'</div>\
                      </div>\
                      <p class="btm_title" data-function="btn_open_table_empty" data-id="'+v.id+'" data-tablename="'+v.label+'">'+v.label+'（空）</p>\
                      </li>').appendTo('#mainPageorderPage .cont_btm');
                    }else{
                        $('<li class="btm_list" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico_box" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">\
                      <div class="btm_ico" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">'+number+'</div>\
                      </div>\
                      <p class="btm_title" data-function="btn_occupy_table_operate" data-id="'+v.id+'" data-orderid="'+v.openBills[0].orderId+'" data-tablename="'+v.label+'">'+v.label+'（就餐中）</p>\
                      </li>').appendTo('#mainPageorderPage .cont_btm');
                    }
                }

            })

            setTimeout(function(){
                $('#mainPageorderPage .cont_btm li').each(function(k,v){
                    if($(v).css("background-color")){
                        $(v).css("background-color","");

                    }
                })
            },2000)

        });
    }
    /*
     * 主页面上直接点餐页面
     * */
    var directClickCpOfMianPage = function(fun){
        $('#subOrderDetailsPage .btmTrue').data('function','btn_orderingFood_directClickCp_cpListInfoOK')
        TakingAnOrder.showDishes(fun);

    }
    /*
     * 今日账单
     * */
    var todayOrderListOfMainPage = function(fun){
        fun();
    }
    /*
     * 预定订单列表
     * */
    var todayOrderListReserveOrderList = function(){
        var parentNode =  $('#subtodayBillOfMealPage');
        var options = {};
        options.start ="";
        options.end ="";
        options.orderType = ['reserve'];
        options.Status = [];
        options.successFunction = function (data) {
            waitPage.closeWaitTime();//关闭等待页面
            TODAYORDERLIST = data.data;
            TODAYORDERSEARCH = 2;
            $('.cont',parentNode).html('');
            $.each(data.data,function(k,v){
                if(v.status=="cancel"){

                }else{
                    if(v.targetLabel){

                    }else{
                        $('<li class="infoList" data-function="btn_open_table_reserve" data-orderid="'+v.id+'">\
                        <p class="time" data-function="btn_open_table_reserve" data-orderid="'+v.id+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="btn_open_table_reserve" data-orderid="'+v.id+'">'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money " data-function="btn_open_table_reserve" data-orderid="'+v.id+'">未落桌</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');

                    }
                }



            })
            $.each(data.data,function(k,v){
                if(v.status=="cancel"){

                }else{
                    if(v.targetLabel){
                        $('<li class="infoList" data-function="acceptWeinXinReserve" data-id="'+v.id+'">\
                        <p class="time" data-function="acceptWeinXinReserve" data-id="'+v.id+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="acceptWeinXinReserve" data-id="'+v.id+'">'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money active" data-function="acceptWeinXinReserve" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                    }else{


                    }
                }

            })
        };
        OrderingSystem.getDayOrdertListByStatus(options);
    }
    /*
     * 外卖订单列表
     * */
    var todayOrderTakeOutOrderList = function(){
        var parentNode =  $('#subtodayBillOfMealPage');
        var options = {};
        options.start ="";
        options.end ="";
        options.orderType = ['takeout'];
        options.Status = [];//"pre","new","confirmed","finished","billed"
        options.successFunction = function (data) {
            waitPage.closeWaitTime();//关闭等待页面
            TODAYORDERLIST = data.data;
            TODAYORDERSEARCH = 3;
            $('.cont',parentNode).html('');
            $.each(data.data,function(k,v){
                var time=new Date(v.time.sec*1000);
                time=time.getHours()+":"+time.getMinutes();
                if(v.status=="pre"){

                    $('<li class="infoList" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">\
                        <p class="time" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">'+time+'</p>\
                    <p class="table" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    <p class="money" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">未处理</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }else{

                    $('<li class="infoList" data-function="btnacceptTakeOut" data-id="'+v.id+'">\
                        <p class="time" data-function="btnacceptTakeOut" data-id="'+v.id+'">'+time+'</p>\
                    <p class="table" data-function="btnacceptTakeOut" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    <p class="money active" data-function="btnacceptTakeOut" data-id="'+v.id+'">已处理</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }

            })
        };
        OrderingSystem.getDayOrdertListByStatus(options);
        /*  //未接受的外卖
         var options = {};
         options.successFunction = function (data) {
         $('.cont',parentNode).html('');
         $.each(data.data,function(k,v){
         var time=new Date(v.time.sec*1000);
         time=time.getHours()+":"+time.getMinutes();
         $('<li class="infoList" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">\
         <p class="time" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">'+time+'</p>\
         <p class="table" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">'+v.targetLabel+'</p>\
         <p class="money" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">未处理</p>\
         </li>').appendTo('#subtodayBillOfMealPage .cont');
         })
         //接受的外卖
         var optionsA = {};
         optionsA.successFunction = function (dataA) {
         $.each(dataA.data,function(k,v){
         var time=new Date(v.time.sec*1000);
         time=time.getHours()+":"+time.getMinutes();
         $('<li class="infoList" data-function="btnacceptTakeOut" data-id="'+v.id+'">\
         <p class="time" data-function="btnacceptTakeOut" data-id="'+v.id+'">'+time+'</p>\
         <p class="table" data-function="btnacceptTakeOut" data-id="'+v.id+'">'+v.targetLabel+'</p>\
         <p class="money active" data-function="btnacceptTakeOut" data-id="'+v.id+'">已处理</p>\
         </li>').appendTo('#subtodayBillOfMealPage .cont');
         });

         };
         OrderingSystem.getTakeoutAcceptedOrderList(optionsA);
         };
         OrderingSystem.getTakeoutAwaitOrderList(options);*/
    }
    /*
     * 结账的订单
     * */
    var todayOrderBillOrderList = function(){
        var parentNode =  $('#subtodayBillOfMealPage');
        var options = {};
        options.start ="";
        options.end ="";
        options.orderType =[];
        options.Status = ["billed"];
        options.successFunction = function (data) {
            waitPage.closeWaitTime();//关闭等待页面
            TODAYORDERLIST =data.data;
            TODAYORDERSEARCH =4;
            $('.cont',parentNode).html('');
            $.each(data.data,function(k,v){
                if(v.orderType=="reserve"){

                    $('<li class="infoList" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">\
                        <p class="time" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+v.targetLabel+'&nbsp;'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money active" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }else{
                    var time=getTimeOrder(v.overTime.sec);
                    $('<li class="infoList" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">\
                        <p class="time" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+time+'</p>\
                    <p class="table" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    <p class="money active" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }
            })
        };
        OrderingSystem.getDayOrdertListByStatus(options);
    }
    /*
     * 已结账的订单详情
     * */
    var alreadyBilledOrderInfo = function(obj,fun){
        var neiHtmlInfo = function(option){
            $('<ul class="cont">\
                <li class="tableInfo">\
                <p class="table">桌号</p>\
                <p class="info">'+option.targetLabel+'</p>\
                </li>\
                    <li class="timeInfo">\
                        <p class="time">时间</p>\
                        <p class="info">'+option.timeEat+'-'+option.timeOver+'</p>\
                    </li>\
                    <div class="orderAndPay">\
                        <div class="billInfo">\
                            <p class="bill">账单</p>\
                            <div class="yeah">'+option.cpList+'\
                            </div>\
                        </div>\
                        <li class="sumInfo">\
                            <p class="sum">共计</p>\
                            <p class="money">￥'+option.total/100+'（预付￥0）</p>\
                        </li>\
                    </div>\
                    <!-- 应收-->\
                    <li class="receivableInfo">\
                        <p class="receivable">应收</p>\
                        <p class="money">￥'+option.total/100+'</p>\
                    </li>\
                    <li class="officialReceiptsInfo">\
                        <p class="officialReceipts">实收</p>\
                        <p class="money">￥'+option.amount/100+'（优惠券'+option.coupon+'）</p>\
                    </li>\
                    <li class="payWayInfo">\
                        <p class="payWay">支付方式</p>\
                        <p class="WayInfo">'+option.payWay+'</p>\
                    </li>\
                    '+option.cpListInfo+'\
                    <div class="btm">已结算</div>\
                </ul>').appendTo('#subtableOrderDetailsPage')
        }
        var oId = obj.data('id');
        OrderingSystem.getOrderById(oId, function (data) {
            $('#subtableOrderDetailsPage').html('');

            fun();
            if(data.data[0].targetValue==0){
                $('.header .headerTitle').html("外卖");
            }else if(data.data[0].targetValue){
                $('.header .headerTitle').html(data.data[0].targetLabel);
            }


            var dataPort=data.data[0];


            var timeOver = getTimeOrder(dataPort.overTime.sec);
            var   timeEat=getTimeOrder(dataPort.time.sec);

            var cpList="";
            var cpListInfo="";
            var coupon="";
            $.each(data.data[0].itemList,function(k,v){
                cpList+=' <p class="dish">'+v.name+'('+v.count+')</p>';
            })
            $.each(data.data[0].itemList,function(k,v){
                cpListInfo+='  <li class="menuList">\
                        <p class="dishesName">'+v.name+'</p>\
                        <p class="price">￥'+v.price/100+'</p>\
                        <p class="count">X '+v.count+'</p>\
                    </li>';
            })
            if(dataPort.tokenList[0]){
                coupon=dataPort.tokenList[0].name;
            }else{
                coupon="无"
            }
            //alert(coupon)

            OrderingSystem.getOrderPayTransByOrderId(oId, function (data) {
                var payWay=""
                $.each(data.data,function(k,v){
                    if(v.amount>0){
                        payWay+=v.payName
                    }

                })

                var options = {};

                options.orderId = oId;
                options.successFunction = function (data) {
                    if(data.data[0]){
                        neiHtmlInfo({
                            targetLabel: dataPort.targetLabel,
                            timeEat:timeEat,
                            timeOver:timeOver,
                            cpList:cpList,
                            total:dataPort.total,
                            amount:dataPort.amount,
                            coupon:coupon,
                            payWay:payWay+'会员支付',
                            cpListInfo:cpListInfo
                        })
                    }else{
                        neiHtmlInfo({
                            targetLabel: dataPort.targetLabel,
                            timeEat:timeEat,
                            timeOver:timeOver,
                            cpList:cpList,
                            total:dataPort.total,
                            amount:dataPort.amount,
                            coupon:coupon,
                            payWay:payWay,
                            cpListInfo:cpListInfo
                        })
                    }
                };
                OrderingSystem.getMemberSpendTransByOrderId(options);


            });

        });
    }
    /*
     * 就餐中
     * */
    var todayOrderEatingFood = function(){
        var parentNode =  $('#subtodayBillOfMealPage');
        OrderingSystem.getTableList(function (data) {
            TABLEHASORDERID={};
            $.each(data.data,function(k,v){
                if(v.openBills[0]){
                    TABLEHASORDERID[v.openBills[0].orderId]=[];
                }

            })
            console.log("TABLEHASORDERID",TABLEHASORDERID)
            var options = {};
            options.start = "";
            options.end =""
            options.orderType =[];
            options.Status = ["new","confirmed","working","finished"];
            options.successFunction = function (data) {
                waitPage.closeWaitTime();//关闭等待页面
                TODAYORDERLIST=data.data;
                TODAYORDERSEARCH = 1;
                $('.cont',parentNode).html('');
                $.each(data.data,function(k,v){
                    if(v.orderType=="reserve"){
                        //alert(TABLEHASORDERID[v.id])
                        if(TABLEHASORDERID[v.id]){
                            $('<li class="infoList" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">\
                        <p class="time" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+v.targetLabel+'&nbsp;'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money " data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                        }

                    }else{
                        if(TABLEHASORDERID[v.id]){
                            var time=getTimeOrder(v.time.sec);
                            $('<li class="infoList" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">\
                        <p class="time" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+time+'</p>\
                    <p class="table" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+v.targetLabel+'</p>\
                    <p class="money " data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                        }

                    }
                })
            };
            OrderingSystem.getDayOrdertListByStatus(options);
        })

    }
    /*
     * 搜索就餐中的订单
     * */
    var searchEatingOrder = function(valueInput){
        console.log("TODAYORDERLIST",TODAYORDERLIST);

        $.each(TODAYORDERLIST,function(k,v){
            if(v.orderType=="reserve"){


                if(TABLEHASORDERID[v.id]){
                    if(v.reserve.name.indexOf(valueInput)>=0||v.targetLabel.indexOf(valueInput)>=0||v.reserve.ResMobile.indexOf(valueInput)>=0){
                        $('<li class="infoList" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">\
                        <p class="time" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+v.targetLabel+'&nbsp;'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money " data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');

                    }

                }
            }else{

                if(TABLEHASORDERID[v.id]){
                    if(v.targetLabel.indexOf(valueInput)>=0){
                        var time=getTimeOrder(v.time.sec);
                        $('<li class="infoList" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">\
                        <p class="time" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+time+'</p>\
                    <p class="table" data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">'+v.targetLabel+'</p>\
                    <p class="money " data-function="btn_occupy_table_operate" data-orderid="'+v.id+'" data-tablename="'+v.targetLabel+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                    }

                }
            }
        })

    }
    /*
     * 搜索预定中的订单
     * */
    var searchReserveOrder = function(valueInput){
        $.each(TODAYORDERLIST,function(k,v){
            if(v.status=="cancel"){

            }else{
                if(v.targetLabel){

                }else{
                    if( v.reserve.ResMobile.indexOf(valueInput)>=0||v.reserve.name.indexOf(valueInput)>=0){
                        $('<li class="infoList" data-function="btn_open_table_reserve" data-orderid="'+v.id+'">\
                        <p class="time" data-function="btn_open_table_reserve" data-orderid="'+v.id+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="btn_open_table_reserve" data-orderid="'+v.id+'">'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money " data-function="btn_open_table_reserve" data-orderid="'+v.id+'">未落桌</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                    }


                }
            }



        })
        $.each(TODAYORDERLIST,function(k,v){
            if(v.status=="cancel"){

            }else{
                if(v.targetLabel){
                    if( v.reserve.ResMobile.indexOf(valueInput)>=0||v.reserve.name.indexOf(valueInput)>=0){
                        $('<li class="infoList" data-function="acceptWeinXinReserve" data-id="'+v.id+'">\
                        <p class="time" data-function="acceptWeinXinReserve" data-id="'+v.id+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="acceptWeinXinReserve" data-id="'+v.id+'">'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money active" data-function="acceptWeinXinReserve" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                    }

                }else{


                }
            }

        })
    }
    /*
     * 搜索外卖中的订单
     * */
    var searchTakeOutOrder = function(valueInput){

        $.each(TODAYORDERLIST,function(k,v){
            var time=new Date(v.time.sec*1000);
            time=time.getHours()+":"+time.getMinutes();
            if(v.status=="pre"){
                if( v.targetLabel.indexOf(valueInput)>=0 ){
                    $('<li class="infoList" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">\
                        <p class="time" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">'+time+'</p>\
                    <p class="table" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    <p class="money" data-function="btnnotacceptTakeOut" data-id="'+v.id+'">未处理</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }

            }else{
                if( v.targetLabel.indexOf(valueInput)>=0 ){
                    $('<li class="infoList" data-function="btnacceptTakeOut" data-id="'+v.id+'">\
                        <p class="time" data-function="btnacceptTakeOut" data-id="'+v.id+'">'+time+'</p>\
                    <p class="table" data-function="btnacceptTakeOut" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    <p class="money active" data-function="btnacceptTakeOut" data-id="'+v.id+'">已处理</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }

            }

        })
    }
    /*
     * 搜索结账的订单
     * */
    var searchBilledOrder = function(valueInput){
        $.each(TODAYORDERLIST,function(k,v){
            if(v.orderType=="reserve"){
                if( v.targetLabel.indexOf(valueInput)>=0||v.reserve.ResMobile.indexOf(valueInput)>=0||v.reserve.name.indexOf(valueInput)>=0){
                    $('<li class="infoList" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">\
                        <p class="time" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+v.reserve.ResTime+'</p>\
                    <p class="table" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+v.targetLabel+'&nbsp;'+v.reserve.name+'&nbsp;电话:'+v.reserve.ResMobile+'</p>\
                    <p class="money active" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }

            }else{
                if( v.targetLabel.indexOf(valueInput)>=0 ){
                    var time=getTimeOrder(v.overTime.sec);
                    $('<li class="infoList" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">\
                        <p class="time" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+time+'</p>\
                    <p class="table" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">'+v.targetLabel+'</p>\
                    <p class="money active" data-function="btn_orderingFood_billOrder_billed" data-id="'+v.id+'">￥'+v.total/100+'</p>\
                    </li>').appendTo('#subtodayBillOfMealPage .cont');
                }

            }
        })
    }
    /*
     * 今日订单搜索
     *   if( v.targetLabel.indexOf(valueInput)>0 ){

     }else if( v.mobile.indexOf(valueInput)>0){

     }
     ( v.reserve.ResMobile.indexOf(valueInput)>0)
     (v.reserve.name.indexOf(valueInput)>0)
     * */
    var todayOrderSearch = function(){
        var parentsNode = $('#subtodayBillOfMealPage');
        var valueInput  = $.trim($('.searchInput',parentsNode).val());
        $('.cont',parentsNode).html('');
        switch(TODAYORDERSEARCH)
        {
            case 1:
                searchEatingOrder(valueInput);//检索正在就餐中的订单
                break;
            case 2:
                searchReserveOrder(valueInput);//检索预定订单
                break;
            case 3:
                searchTakeOutOrder(valueInput);//检索外卖订单
                break;
            case 4:
                searchBilledOrder(valueInput);//检索结账的订单
                break;
        }




    }
    /*******************************（任务，点餐，更多，我的）的函数结束****************************************/
    /**********************主要函数开始*********************************************/
    /*
     * 记录浏览历史，给页面的返回按钮，和手机自带的返回按钮，可以返回到上一页
     * */
    var history_record=function(e){
        /************用于防止push 进重复页面 *****/
        if(e && e !=lastPage_record){

            //TODO:记得打开
            //history.pushState({label:e});
            lastPage_record=e;
            //alert("PUSHED:"+e);
        }
        history.pushState({label:e},"");
    }
    var active=function(obj){
        obj.on('click',function(ev){
            //alert($(ev.target).hasClass('active'))
            if($(ev.target).hasClass('active')){
                $(ev.target).removeClass('active')
            }else{
                $(ev.target).addClass('active');
            }
            /*
             obj.removeClass('active');
             $(ev.target).addClass('active');*/
            /* if($(ev.target).hasClass('active')){$(ev.target).removeClass('active');return};
             obj.removeClass('active');
             $(ev.target).addClass('active');*/
        });
    };
    /*
     * 给页面所有的东西加载事件
     * */
    var bindEvent=function(){
//TODO:test FastClick change touchstart to click
        $(document).on('click',function(ev){//给document添加点击事件代理
            clearInterval(SETINTERVALFLAG.addCp)
            for(a in clickArea){
                if($(ev.target).data('function')==a){
                    var target = $(ev.target).data('target');
                    if( target ){
                        clickArea[a]($(ev.target),target);
                    };
                    clickArea[a]($(ev.target));
                }
            }
        });

        $(document).on('touchstart',function(ev){//给document添加点击事件代理
            for(a in clickArea){
                if($(ev.target).data('functionb')==a){
                    clickArea[a]($(ev.target));
                }
            }
        });
        $(document).on('touchend',function(ev){//给document添加点击事件代

            for(a in clickArea){
                if($(ev.target).data('functionb')==a){
                    $('#suborderDishesPage .dishesMenuList').find('.cut').removeClass('disabled');
                    $('#suborderDishesPage .dishesMenuList').find('.add ').removeClass('disabled');
                    $('#subOrderDetailsPage .ul-cpListOrderInfo').find('.cutIco ').removeClass('disabled');
                    $('#subOrderDetailsPage .ul-cpListOrderInfo').find('.addIco ').removeClass('disabled');
                    clearInterval(SETINTERVALFLAG.addCp)
                }
            }
        });
        $(document).on('touchmove',function(ev){//给document添加点击事件代理
            $('.cpPageFooterFatherNode .barAndKeysDown').removeClass('barAndKeysUp');
            $('.cpPageFooterFatherNode .keysIcoWhite').removeClass('active');
            for(a in clickArea){
                if($(ev.target).data('functionb')==a){
                    $('#suborderDishesPage .dishesMenuList').find('.cut').removeClass('disabled');
                    $('#suborderDishesPage .dishesMenuList').find('.add').removeClass('disabled');
                    $('#subOrderDetailsPage .ul-cpListOrderInfo').find('.cutIco ').removeClass('disabled');
                    $('#subOrderDetailsPage .ul-cpListOrderInfo').find('.addIco ').removeClass('disabled');
                    clearInterval(SETINTERVALFLAG.addCp)
                }
            }
        });
//Touchend to click
        $(document).on('Touchend',function(ev){//预先设定一个元素（html中写上data-active="active"）下面的一级子元素只能有一个保持active状态
            for(a in clickArea){
                if($(ev.target).parent().data('active')==a){
                    clickArea[a]($(ev.target));
                }
            }
        });

        //TODO:又绑了一遍active，梳理active
        for( var i=0; i<arrActive.length;i++){ active( $(arrActive[i]) ) }
    };
    /*
     * 返回按钮
     * */
    var backwardEventHandle=function(){
        window.onpopstate = function (event) {
            if(historyList.length<2){ return console.log('没有更早的记录了！'); }
            historyList.pop();
            showPage( $('#'+historyList[historyList.length-1]),{record:true} )();
            if(BACKADDPORTEVENT.openTable.length>0){
                BACKADDPORTEVENT.openTable.pop();
                if(BACKADDPORTEVENT.openTable.length==0){
                    OpenTable.clickBackCanlOrder();
                    //alert(1)
                }
            }
            /*   if (event.state) {
             //labelOutput.textContent = event.state.label;
             //alert("backward");
             //alert(JSON.stringify(event.state))
             showPage($('#'+event.state.label),{record:true} )();

             } else {
             // alert("last Page");
             }*/
        }

    }
    /*
     * 菜品每次加很多或者减很多
     * */
    function cPaddMoreOrSubMore(fun){
        var i=0;
        SETINTERVALFLAG.addCp = setTimeout(function(){
            /*     i++;
             if(i>10){
             clearInterval(SETINTERVALFLAG.addCp)
             }
             if(CPTOTALNUMBER<0){
             clearInterval(SETINTERVALFLAG.addCp)
             }*/
            if(SETINTERVALFLAG.oneCpNumber<=0){
                clearTimeout(SETINTERVALFLAG.addCp)
            }else if(SETINTERVALFLAG.oneCpNumber>=99){
                clearTimeout(SETINTERVALFLAG.addCp)
            }else if(CPTOTALNUMBER<=0){
                clearTimeout(SETINTERVALFLAG.addCp)
            }else{
                fun();
                cPaddMoreOrSubMore(fun);
            }


        },100)
    }
    /*
     * obj主页面的$(id),option={record:true/false}
     * */
    var showPage=function(obj,option){
        return function(){



            var record = null;
            if(option){record = option.record};

            if(obj[0].id == "mainPagetaskPage"){
                taskMainPage();
            }else{
                waitPage.closeWaitTime();//关闭等待页面
            }
            if(!obj) return console.log('要找的页面不存在！！');
            if(!record){
                //console.log(obj);
                switch(obj[0].id)
                {
                    case "suborderMainPage":
                        historyList.push("mainPagetaskPage");
                        history.replaceState({label:"mainPagetaskPage"},"");
                        break;
                    case "subTakeoutMainPage":
                        historyList.push("mainPagetaskPage");
                        history.replaceState({label:"mainPagetaskPage"},"");
                        break;
                    case "subMemberSearch":
                        historyList.push("mainPageorderPage");
                        history.replaceState({label:"mainPageorderPage"},"");
                        break;
                    case "subtodayBillOfMealPage":
                        historyList.push("mainPageorderPage");
                        history.replaceState({label:"mainPageorderPage"},"");
                        break;
                    /*case "subchoosePayWayPage":
                     historyList.push("subchangeOneSeatPage");
                     history.replaceState({label:"subchangeOneSeatPage"},"");
                     break;*/
                    case "subchangeOneSeatPage":
                        historyList.push("mainPageorderPage");
                        history.replaceState({label:"mainPageorderPage"},"");
                        break;
                }
                historyList.push(obj[0].id);
                //alert(obj[0].id)
                history_record(obj.attr('id'));
                //alert("record"+obj.attr('id'));

            }



            if(obj.data('belongtomenu') !='none'){//页面级元素必须加上data-belongToMenu
                //console.log(obj.data('belongtomenu'));

                if(obj.data('belongtomenu') == 'index'){ serviceBox.show();}
                else{serviceBox.hide();}
                //alert(obj.data('belongtomenu'))
                $('.footer').show();
                $('.footer').find('.active').removeClass('active')
                $('.footer .'+obj.data('belongtomenu')).addClass('active')



            }else{
                serviceBox.hide();//有下角的服务呼叫
                $('.footer').hide();//nav是最下面的三个导航按钮
            }
            //判断header的返回隐藏或显示

            if(obj.data('belongtoheader').back){
                $('.header .headerBack').show();
            }else{
                $('.header .headerBack').hide();
            }
            //判断header的搜索隐藏或显示，把字变化
            $('.header .headerTitle').html(obj.data('title'))
            console.log(obj.data('belongtoheader').search)
            if(obj.data('belongtoheader').search){
                $('.header .headerSearch').show();
            }else{
                $('.header .headerSearch').hide();
            }
            //判断header的扫码隐藏或显示
            if(obj[0].id=="subhandOverWorkPage"){  //判断是否查询
                $('.header .select').show();
            }else if(obj[0].id=="subperformancePage"){
                $('.header .select').show();
            }else if(obj[0].id=="subMemberSearch"){
                $('.header .Addto').show();
            }else{
                $('.header .select').hide();
                $('.header .Addto').hide();
            }
            //alert(obj.data('belongtoheader').scancode)
            if(obj.data('belongtoheader').scancode){
                $('.header .headerScanCode').show();
            }else{
                $('.header .headerScanCode').hide();
            }
            //判断header的添加隐藏或显示
            if(obj.data('belongtoheader').add){
                $('.header .headerAdd').show();
            }else{
                $('.header .headerAdd').hide();
            }
//        隐藏其他页面，显示本页面
            console.log(obj)

            $('.main-page').hide();
            obj.show();

            for( var i=0; i<arrActive.length;i++){ active( $(arrActive[i]) ) }//重新执行额外绑定的active;防止新增的元素没有active事件
        };

    }
    /*
     * 获得今日，明天，后天
     * */
    var getDate=function(date){

        var dataOfPort=date;
        var timeNew=new Date();
        var timeNewArray=[]
        var timeArra=['今日','明天','后天'];
        var timeArray=[];
        timeArray[0]=timeNew.getFullYear();
        timeArray[1]=(timeNew.getMonth()+1);
        timeArray[2]=timeNew.getDate()
        timeNew=timeArray.join("");
        var timeS=dataOfPort.split('-').join("");

        if(timeArra[(timeS-timeNew)]){
            return timeArra[(timeS-timeNew)];
        }else{
            return "过期"
        }

    }
    /*
     * 任务界面上的外卖预定数量
     * */
    var notAcceptReserveAndTakeOutNumberOnTaskPage = function(){
        /*
         * 未接受的预定数量
         * */
        var options = {};
        options.successFunction = function (data) {
            $('#mainPagetaskPage .reserveListMainPageTask').html('');
            if(data.data[0].reserve==0){
                $('<dl data-function="notAcceptReserve">\
                <div class="listOrderImg" data-function="notAcceptReserve"></div>\
                    <dt data-function="notAcceptReserve">预定</dt>\
                    <dd data-function="notAcceptReserve"></dd>\
                    <div class="time" data-function="notAcceptReserve"></div>\
                    <div class="alt task-reserve-not-accept-number" data-function="notAcceptReserve">0</div>\
                </dl>').appendTo('#mainPagetaskPage .reserveListMainPageTask')
            }else{
                if(data.data[0].New.length==0){

                }else{
                    var time= getDate(data.data[0].New.reserve.ResDate);
                    $('<dl data-function="notAcceptReserve">\
                <div class="listOrderImg" data-function="notAcceptReserve"></div>\
                    <dt data-function="notAcceptReserve">预定</dt>\
                    <dd data-function="notAcceptReserve">微信预定'+data.data[0].New.reserve.tableClassName+'，今日'+data.data[0].New.reserve.ResTime+'用餐</dd>\
                    <div class="time" data-function="notAcceptReserve">'+data.data[0].New.reserve.ResTime+'</div>\
                    <div class="alt task-reserve-not-accept-number" data-function="notAcceptReserve">'+data.data[0].reserve+'</div>\
                </dl>').appendTo('#mainPagetaskPage .reserveListMainPageTask')
                }
            }



            /*
             * 未接受的外卖数量
             * */
            var options = {};
            options.successFunction = function (dataw) {
                $('#mainPagetaskPage .takeOutListMainPageTask').html('');                var memberName='';
                if(dataw.data[0].takeout==0){
                    $('  <dl data-function="notAcceptTakeOutPage">\
                    <div class="listTakeoutImg"  data-function="notAcceptTakeOutPage"></div>\
                        <dt data-function="notAcceptTakeOutPage">外卖</dt>\
                        <dd data-function="notAcceptTakeOutPage"></dd>\
                        <div class="time" data-function="notAcceptTakeOutPage"></div>\
                        <div class="alt task-take-out-not-accept-number" data-function="notAcceptTakeOutPage">0</div>\
                    </dl>').appendTo('#mainPagetaskPage .takeOutListMainPageTask');
                }else{
                    if(dataw.data[0].New.name==""){
                        memberName='';
                    }else{
                        memberName=dataw.data[0].New.name+'，';
                    }
                    if(dataw.data[0].New.length==0){

                    }else{
                        var time=new Date(dataw.data[0].New.time.sec*1000);
                        time=time.getHours()+":"+time.getMinutes();
                        $('  <dl data-function="notAcceptTakeOutPage">\
                    <div class="listTakeoutImg"  data-function="notAcceptTakeOutPage"></div>\
                        <dt data-function="notAcceptTakeOutPage">外卖</dt>\
                        <dd data-function="notAcceptTakeOutPage">'+memberName+'电话：'+dataw.data[0].New.memberMobile+'</dd>\
                        <div class="time" data-function="notAcceptTakeOutPage">'+time+'</div>\
                        <div class="alt task-take-out-not-accept-number" data-function="notAcceptTakeOutPage">'+dataw.data[0].takeout+'</div>\
                    </dl>').appendTo('#mainPagetaskPage .takeOutListMainPageTask');
                    }
                }




                //$('.task-take-out-not-accept-number').html(data.data[0].takeout);
            };
            OrderingSystem.getTakeoutAwaitOrderCount(options);
            //$('.task-reserve-not-accept-number').html(data.data[0].reserve);
        };
        OrderingSystem.getReserveAwaitOrderCount(options);

    }
    /*
     * 任务界面服务列表
     * */
    var taskServiceList  = function(){
        $('.taskMainServiceList').html('');
        var options = {};
        options.successFunction = function (data) {
            $('.taskMainServiceList').html('');
            //获得接受完成的服务
            var options = {};
            options.startDay = "";
            options.endDay ="";
            options.StatusType=["complete"]
            options.successFunction = function (dataC) {
                var options = {};
                options.successFunction = function (dataN) {
                    $('.taskMainServiceList').html('');
                    waitPage.closeWaitTime();//关闭等待页面
                    //加菜提醒
                    $.each(dataN.data[0],function(k,v){
                        var time=new Date(v.newLabel.time.sec*1000);
                        time=time.getHours()+':'+time.getMinutes();
                        $('<dl  data-function="btn_taskNotAcceptNewLineItem" data-id="'+v.newLabel.orderId+'">\
                   <div class="listImg" data-function="btn_taskNotAcceptNewLineItem"></div>\
                       <dt class="contTitle" data-function="btn_taskNotAcceptNewLineItem">'+ v.newLabel.Label+'</dt>\
                       <dd class="contArtitle" data-function="btn_taskNotAcceptNewLineItem">加餐处理，'+v.newLabel.Item.join("、")+'</dd>\
                       <div class="time" data-function="btn_taskNotAcceptNewLineItem">'+time+'</div>\
                       <div class="contDot" style="display: none" data-function="btn_taskNotAcceptNewLineItem"></div>\
                   </dl>').appendTo('.taskMainServiceList');
                    })
                    //未接受的服务
                    $.each(data.data[0].new,function(k,v){
                        var time=new Date(v.time.sec*1000);
                        time=time.getHours()+':'+time.getMinutes();
                        var tId =v.TId;
                        OrderingSystem.getTableById(tId, function (data) {
                            $('<dl  data-function="btn_taskNotAcceptServiceList" data-id="'+v.id+'">\
                   <div class="listImg" data-function="btn_taskNotAcceptServiceList"></div>\
                       <dt class="contTitle" data-function="btn_taskNotAcceptServiceList">'+data.data[0].label+'</dt>\
                       <dd class="contArtitle" data-function="btn_taskNotAcceptServiceList">'+v.detail+'</dd>\
                       <div class="time" data-function="btn_taskNotAcceptServiceList">'+time+'</div>\
                       <div class="contDot" data-function="btn_taskNotAcceptServiceList"></div>\
                   </dl>').appendTo('.taskMainServiceList');
                        });

                    })
                    //已经完成的服务
                    $.each(dataC.data,function(k,v){

                        var time=new Date(v.time.sec*1000);
                        time=time.getHours()+':'+time.getMinutes();
                        var tId =v.TId;
                        OrderingSystem.getTableById(tId, function (data) {
                            $('<dl data-function="btn_taskAcceptServiceList" data-id="'+v.id+'">\
                   <div class="listImg"  data-function="btn_taskAcceptServiceList"></div>\
                       <dt class="contTitle" data-function="btn_taskAcceptServiceList">'+data.data[0].label+'</dt>\
                       <dd class="contArtitle" data-function="btn_taskAcceptServiceList">'+v.detail+'</dd>\
                       <div class="time" data-function="btn_taskAcceptServiceList">'+time+'</div>\
                       <div class="contDot" style="display: none" data-function="btn_taskAcceptServiceList"></div>\
                   </dl>').appendTo('.taskMainServiceList');
                        });

                    })
                };
                OrderingSystem.getTableByNormalNewLineItem(options);

            };
            OrderingSystem.getLoginAfterwardsCompleteService(options);


        };
        OrderingSystem.getMyNotCompleteServiceList(options);
    }
    /*
     * 显示或者隐藏等待页面
     * */
    var waitPage = {
        closeflag:null,
        /*显示等待时间*/showWaitTime : function(){
            $(".wait_gear").fadeIn(100);
            var i=0;
            this.closeflag= setInterval(function(){
                i++;
                if(i==1){
                    $('.gear').css('background-position','0 -104px')
                }else if(i==2){
                    $('.gear').css('background-position','0 -181px')

                }else if(i==3){
                    $('.gear').css('background-position','0 -250px')
                    i=0;
                }else if(i==4){
                    $('.gear').css('background-position','0 -316px')
                    i=0;
                }

            },100)
        },
        /*关闭等待时间*/closeWaitTime :function(){
            $(".wait_gear").fadeOut(100);
            clearInterval(this.closeflag);
        }
    }


    var showInitPage =    showPage($('#subloginPage'));//展示首页
    return{
        init:function(){
            showInitPage();//显示首页
            bindEvent();//给页面所有带有data-function的节点添加事件
            backwardEventHandle();//页面上的返回按钮
            notAcceptReserveAndTakeOutNumberOnTaskPage();//任务界面的未接受预定外卖数量

        }
    }
}();